function debounce(func, delay) {
  let timer;
  return function () {
    clearTimeout(timer);
    timer = setTimeout(func, delay);
  };
}

class CanvasLoop {
  constructor (el, imageList, config) {
    if (!el) {
      throw Error("el params is not ignore");
    }

    if (!Array.isArray(imageList)) {
      throw Error("imageList params is must Array");
    }

    if (imageList.length < 2) {
      throw Error("imageList.length must > 2");
    }

    this.contanier = el
    this.imageList = imageList
    this.config = Object.assign({}, {}, config)

    this.ISLOOP = false

    this._W = 0
    this._H = 0

    window.addEventListener(
      "resize",
      debounce(() => {
        // clearTimeout(this.loopTimeout);
        this.initLoop();
      }),
      500
    );
  }

}

const initCanvasLoop = (el, imageList, config) => new CanvasLoop(el, imageList, config)

export default initCanvasLoop
